<!--
 * @Author: your name
 * @Date: 2020-11-15 13:02:43
 * @LastEditTime: 2020-11-15 13:42:42
 * @LastEditors: Please set LastEditors
 * @Description: 考试筛选组件
 * @FilePath: \cloudEdu\src\components\selectExam.vue
-->
<template>
  <div class="selectExam">
    <el-form ref="form" label-width="80px" :inline="true">
      <el-form-item label="考试类型:">
        <el-select v-model="exam.typeId" placeholder="请选择考试类型" @change="changeTypeList">
          <el-option v-for="item in exam.typeList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工种类型:">
        <el-select v-model="exam.workId" placeholder="请选择工种类型" @change="changeWorkList">
          <el-option v-for="item in exam.workList" :key="item.workTypeId" :label="item.name" :value="item.workTypeId"> </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "SelectExam",
  data() {
    return {
      exam: {
        typeId: "",
        typeList: [
          { name: "全部", id: "" },
          { name: "一级考试", id: 1 },
          { name: "二级考试", id: 2 },
          { name: "三级考试", id: 3 }
        ],
        workId: "",
        workList: []
      }
    };
  },
  mounted() {
    let that = this;
    let time = new Date().valueOf();
    that
      .$http({
        url: "/wisdomlearn/base/selectAllWorkType",
        method: "post",
        headers: {
          accessToken: that.config.token,
          appId: "appid-xinyun-0003",
          userId: JSON.parse(that.tool.getCookie("xinyun-front-userInfo")).userId,
          clientId: "",
          sign: that.tool.sign("/wisdomlearn/base/selectAllWorkType", time),
          timestamp: time
        }
      })
      .then(res => {
        if (res.retCode === "00000") {
          res.data.unshift({ workTypeId: "", name: "全部" });
          this.exam.workList = res.data;
        }
      })
      .catch(err => {
        console.log(err);
      });
  },
  methods: {
    // 恢复全部
    setDefaultType() {
      this.exam.typeId = "";
      this.exam.workId = "";
    },
    changeTypeList(value) {
      this.$emit("changeTypeList", value);
    },
    changeWorkList(value) {
      this.$emit("changeWorkList", value);
    }
  }
};
</script>

<style scoped>
.selectExam .el-select:nth-child(2) {
  margin-left: 15px;
}
</style>
